﻿using Microsoft.Extensions.Logging;
using MQTTnet.Protocol;
using MQTTnet.Server;
using System;
using System.Threading.Tasks;

namespace Mqtt.Callback.Handlers
{
    public class MqttValidatorInfo
    {

    }
    /// <summary>
    /// mqtt连接验证
    /// </summary>
    public class MqttServerConnectionValidator : IMqttServerConnectionValidator
    {
        private readonly ILogger _logger;
        public MqttServerConnectionValidator( ILogger<MqttServerConnectionValidator> logger)
        {
            this._logger = logger ?? throw new ArgumentNullException(nameof(logger));
        }

        public Task ValidateConnectionAsync(MqttConnectionValidatorContext context)
        {
           
            //ip 端口 不为空
            if (string.IsNullOrWhiteSpace(context.Endpoint))
            {
                context.ReasonCode = MqttConnectReasonCode.BadAuthenticationMethod;
                return Task.CompletedTask;
            }
            context.ReasonCode = MqttConnectReasonCode.Success;
            return Task.CompletedTask;
        }
    }
}
